package userandright

import (
	"sync"
	"time"

	"gitee.com/tomatomeatman/golang-repository/bricks2/model/dbinfo"
	"gitee.com/tomatomeatman/golang-repository/bricks2/utils/gorm"
)

var tableInfo *dbinfo.TableInfo
var tableOnce sync.Once

/**
 * 初始化
 */
func init() {
	dbinfo.RegisterEntity("UserAndRightBase", &UserAndRightBase{}) //注册注册数据库实体类结构体
}

/**
 * 用户权限表'user_and_right'表结构体
 * 警告:非数据库字段禁止在此添加,应该创建扩展结构体中添加
 * @author HuangXinBian
 */
type UserAndRightBase struct {
	Id           int64     `json:"id" gorm:"column:id; type:bigintAUTO_INCREMENT; NOT NULL; primary_key" defaultData:"0" comment:"记录编号"`
	UserId       string    `json:"userId" gorm:"column:user_id; type:varchar; NOT NULL" defaultData:"''" comment:"用户编号"`
	RightId      string    `json:"rightId" gorm:"column:right_id; type:varchar; NOT NULL" defaultData:"''" comment:"权限编号"`
	Type         int       `json:"type" gorm:"column:type; type:int; DEFAULT '1'" defaultData:"1" comment:"权限类型"`
	Memo         string    `json:"memo" gorm:"column:memo; type:varchar" defaultData:"''" comment:"备注"`
	Creator      string    `json:"creator" gorm:"column:creator; type:varchar; NOT NULL; DEFAULT '00000000'" defaultData:"'00000000'" comment:"创建者"`
	CreateDate   time.Time `json:"createDate" gorm:"column:create_date; type:datetime; NOT NULL" defaultData:"'2025-03-24 10:33:56'" comment:"创建时间"`
	Modifieder   string    `json:"modifieder" gorm:"column:modifieder; type:varchar; NOT NULL; DEFAULT '00000000'" defaultData:"'00000000'" comment:"修改人"`
	ModifiedDate time.Time `json:"modifiedDate" gorm:"column:modified_date; type:datetime; NOT NULL" defaultData:"'2025-03-24 10:33:56'" comment:"修改时间"`
	State        int       `json:"state" gorm:"column:state; type:int; NOT NULL; DEFAULT '1'" defaultData:"1" comment:"状态"`
	Rank         int       `json:"rank" gorm:"column:rank; type:int; NOT NULL; DEFAULT '1'" defaultData:"1" comment:"序号"`
	Edition      int       `json:"edition" gorm:"column:edition; type:int; NOT NULL; DEFAULT '1'" defaultData:"1" comment:"版本号"`
}

/**
 * 创建结构实体
 * @return
 */
func (UserAndRightBase) New() dbinfo.Entity {
	return &UserAndRightBase{}
}

/**
 * 取基础实体,用于在子类(嵌套结构体)时同样获得基类
 */
func (UserAndRightBase) BaseEntity() dbinfo.Entity {
	return &UserAndRightBase{}
}

/**
 * 结构体映射表名,处理结构体名称与表名不一致的情况
 * @return
 */
func (entity UserAndRightBase) TableName() string {
	entity.TableInfo()
	return tableInfo.TableFullName
}

/**
 * 结构体映射库名,去除'Dev_'等前缀
 * @return
 */
func (entity UserAndRightBase) OwnerName() string {
	entity.TableInfo()
	return tableInfo.DbObj
}

/**
 * 结构体映射表名,无库名
 * @return
 */
func (entity UserAndRightBase) OwnerTable() string {
	entity.TableInfo()
	return tableInfo.TableName
}

/**
 * 结构体的属性名串(首字母小写)
 * @return
 */
func (UserAndRightBase) BaseColumnNames() string {
	return "id,user_id,right_id,type,memo,creator,create_date,modifieder,modified_date,state,rank,edition"
}

/**
 * 取数据结构信息
 * @param name 属性名
 * @return
 */
func (UserAndRightBase) GetDataInfo(name string) *dbinfo.DataInfo {
	switch name {
	case "id":
		return &dbinfo.DataInfo{DbObj: "BaseSystem", DbName: "base_system", TableName: "user_and_right", Field: "id", Name: "Id", JsonName: "id", Comment: "记录编号", IsDbField: true, DbFileType: "bigint", DefaultData: "", GoDefaultData: 0, IsExtra: true, IsKey: true, IsNull: false, MaxLength: 20, IsDecimal: false, IntLength: 20, DecimalLength: 0, Index: 0, IsBigTxt: false}
	case "userId":
		return &dbinfo.DataInfo{DbObj: "BaseSystem", DbName: "base_system", TableName: "user_and_right", Field: "user_id", Name: "UserId", JsonName: "userId", Comment: "用户编号", IsDbField: true, DbFileType: "varchar", DefaultData: "", GoDefaultData: "", IsExtra: false, IsKey: false, IsNull: false, MaxLength: 8, IsDecimal: false, IntLength: 8, DecimalLength: 0, Index: 1, IsBigTxt: false}
	case "rightId":
		return &dbinfo.DataInfo{DbObj: "BaseSystem", DbName: "base_system", TableName: "user_and_right", Field: "right_id", Name: "RightId", JsonName: "rightId", Comment: "权限编号", IsDbField: true, DbFileType: "varchar", DefaultData: "", GoDefaultData: "", IsExtra: false, IsKey: false, IsNull: false, MaxLength: 20, IsDecimal: false, IntLength: 20, DecimalLength: 0, Index: 2, IsBigTxt: false}
	case "type":
		return &dbinfo.DataInfo{DbObj: "BaseSystem", DbName: "base_system", TableName: "user_and_right", Field: "type", Name: "Type", JsonName: "type", Comment: "权限类型", IsDbField: true, DbFileType: "int", DefaultData: "1", GoDefaultData: 1, IsExtra: false, IsKey: false, IsNull: true, MaxLength: 11, IsDecimal: false, IntLength: 11, DecimalLength: 0, Index: 3, IsBigTxt: false}
	case "memo":
		return &dbinfo.DataInfo{DbObj: "BaseSystem", DbName: "base_system", TableName: "user_and_right", Field: "memo", Name: "Memo", JsonName: "memo", Comment: "备注", IsDbField: true, DbFileType: "varchar", DefaultData: "", GoDefaultData: "", IsExtra: false, IsKey: false, IsNull: true, MaxLength: 200, IsDecimal: false, IntLength: 200, DecimalLength: 0, Index: 4, IsBigTxt: false}
	case "creator":
		return &dbinfo.DataInfo{DbObj: "BaseSystem", DbName: "base_system", TableName: "user_and_right", Field: "creator", Name: "Creator", JsonName: "creator", Comment: "创建者", IsDbField: true, DbFileType: "varchar", DefaultData: "00000000", GoDefaultData: "00000000", IsExtra: false, IsKey: false, IsNull: false, MaxLength: 8, IsDecimal: false, IntLength: 8, DecimalLength: 0, Index: 5, IsBigTxt: false}
	case "createDate":
		return &dbinfo.DataInfo{DbObj: "BaseSystem", DbName: "base_system", TableName: "user_and_right", Field: "create_date", Name: "CreateDate", JsonName: "createDate", Comment: "创建时间", IsDbField: true, DbFileType: "datetime", DefaultData: "", GoDefaultData: time.Now().Format("2006-01-02 15:04:05"), IsExtra: false, IsKey: false, IsNull: false, MaxLength: 23, IsDecimal: false, IntLength: 23, DecimalLength: 0, Index: 6, IsBigTxt: false}
	case "modifieder":
		return &dbinfo.DataInfo{DbObj: "BaseSystem", DbName: "base_system", TableName: "user_and_right", Field: "modifieder", Name: "Modifieder", JsonName: "modifieder", Comment: "修改人", IsDbField: true, DbFileType: "varchar", DefaultData: "00000000", GoDefaultData: "00000000", IsExtra: false, IsKey: false, IsNull: false, MaxLength: 8, IsDecimal: false, IntLength: 8, DecimalLength: 0, Index: 7, IsBigTxt: false}
	case "modifiedDate":
		return &dbinfo.DataInfo{DbObj: "BaseSystem", DbName: "base_system", TableName: "user_and_right", Field: "modified_date", Name: "ModifiedDate", JsonName: "modifiedDate", Comment: "修改时间", IsDbField: true, DbFileType: "datetime", DefaultData: "", GoDefaultData: time.Now().Format("2006-01-02 15:04:05"), IsExtra: false, IsKey: false, IsNull: false, MaxLength: 23, IsDecimal: false, IntLength: 23, DecimalLength: 0, Index: 8, IsBigTxt: false}
	case "state":
		return &dbinfo.DataInfo{DbObj: "BaseSystem", DbName: "base_system", TableName: "user_and_right", Field: "state", Name: "State", JsonName: "state", Comment: "状态", IsDbField: true, DbFileType: "int", DefaultData: "1", GoDefaultData: 1, IsExtra: false, IsKey: false, IsNull: false, MaxLength: 11, IsDecimal: false, IntLength: 11, DecimalLength: 0, Index: 9, IsBigTxt: false}
	case "rank":
		return &dbinfo.DataInfo{DbObj: "BaseSystem", DbName: "base_system", TableName: "user_and_right", Field: "rank", Name: "Rank", JsonName: "rank", Comment: "序号", IsDbField: true, DbFileType: "int", DefaultData: "1", GoDefaultData: 1, IsExtra: false, IsKey: false, IsNull: false, MaxLength: 11, IsDecimal: false, IntLength: 11, DecimalLength: 0, Index: 10, IsBigTxt: false}
	case "edition":
		return &dbinfo.DataInfo{DbObj: "BaseSystem", DbName: "base_system", TableName: "user_and_right", Field: "edition", Name: "Edition", JsonName: "edition", Comment: "版本号", IsDbField: true, DbFileType: "int", DefaultData: "1", GoDefaultData: 1, IsExtra: false, IsKey: false, IsNull: false, MaxLength: 11, IsDecimal: false, IntLength: 11, DecimalLength: 0, Index: 11, IsBigTxt: false}
	default:
		return nil
	}
}

/**
 * 结构体映射表简化信息
 * @return
 */
func (UserAndRightBase) TableInfo() *dbinfo.TableInfo {
	tableOnce.Do(func() {
		tableInfo = &dbinfo.TableInfo{
			DbName:          "base_system",
			DbObj:           "BaseSystem",
			TableFullName:   "",
			TableName:       "user_and_right",
			TableObj:        "UserAndRight",
			KeyName:         "Id",
			KeyJson:         "id",
			KeyField:        "id",
			KeyFields:       "id,",
			KeyLen:          20,
			AutoKey:         true,
			HasPid:          false,
			HasPath:         false,
			HasRecordKey:    false,
			HasMemo:         true,
			HasCreator:      true,
			HasCreateDate:   true,
			HasModifieder:   true,
			HasModifiedDate: true,
			HasState:        false,
			HasRank:         true,
			HasEdition:      true,
			HasPassword:     false,
			HasSign:         false,
			HasOnlyign:      false,
			HasDelSign:      false,
			BigTextFields:   "",
		}

		tableInfo.TableFullName = gorm.GetDbName(tableInfo.DbObj) + tableInfo.TableName
	})

	return tableInfo
}
